package com.seari.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.seari.bean.AlarmCountMalfunction;
import com.seari.bean.AlarmMessageBean;
import com.seari.bean.AlarmQuery;
import com.seari.bean.AllLineRealAlarm;
import com.seari.bean.AllLineStationFault;
import com.seari.bean.HealthImportDevice;
import com.seari.main.StartUpClass;
import com.seari.pojo.MessageBean;
import com.seari.pojo.QueryBase;
import com.seari.service.AlarmService;
import com.seari.utils.PropertiesUtil;
import com.seari.utils.StringHelper;


@Controller
public class AlarmController {

    @Autowired
    private AlarmService alarmService;
    protected static Logger logger = LoggerFactory.getLogger(AlarmController.class);

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 首页线路图故障趋势
     *
     * @return
     */
    @RequestMapping("/alarm/indexGetAlarmTrend")
    @ResponseBody
    public MessageBean indexGetAlarmTrend() {
        MessageBean messageBean = new MessageBean();
        Map<String, int[]> resultMap = new HashMap<>();
        if (StartUpClass.indexGetAlarmTrend.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            int[] yData1 = new int[]{
                    10000, 9930, 9300, 9040, 8090, 8077, 9300, 8064, 7082, 6709, 6500, 8023
            };
            int[] yData2 = new int[]{
                    12000, 9430, 9500, 8040, 8590, 8377, 6600, 8464, 7682, 8709, 7500, 7023
            };
            resultMap.put("yData1", yData1);
            resultMap.put("yData2", yData2);
            messageBean.setData(resultMap);
        } else {
        }
        return messageBean;
    }

    /**
     * 首页线路图各专业故障统计
     *
     * @return
     */
    @RequestMapping("/alarm/indexGetAlarmByType")
    @ResponseBody
    public MessageBean indexGetAlarmByType() {
        MessageBean messageBean = new MessageBean();
        List<Map> typeList = new ArrayList<Map>();
        Map<String, Object> indexMap = new HashMap<>();
        if (StartUpClass.indexGetAlarmByType.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            indexMap.put("EMCS", 2234);
            indexMap.put("FAS", 2311);
            indexMap.put("PSCADA", 321);

            Set entrySet = indexMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);
        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<AlarmCountMalfunction> alarmCountMalfunctions = alarmService.queryAlarmMalfunction();
            for (AlarmCountMalfunction alarmCountMalfunction : alarmCountMalfunctions) {
                indexMap.put(alarmCountMalfunction.getAlarmSystem(), alarmCountMalfunction.getCntAlarmSystem());

            }
            Set entrySet = indexMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);
        }
        return messageBean;
    }

    /**
     * 首页线路图车站故障统计TOP10
     *
     * @return
     */
    @RequestMapping("/alarm/indexGetAlarmTop")
    @ResponseBody
    public MessageBean indexGetAlarmTop() {
        MessageBean messageBean = new MessageBean();
        Map<String, Object> resultMap = new HashMap<>();
        if (StartUpClass.indexGetAlarmTop.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            String[] xData = new String[]{
                    "龙阳路", "老西门", "大连路", "石龙路", "宁国路", "徐家汇", "东兰路", "巨峰路", "陆家嘴", "市光路"
            };
            int[] yData = new int[]{
                    1000, 993, 930, 904, 890, 877, 864, 782, 679, 650
            };
            resultMap.put("xData", xData);
            resultMap.put("yData", yData);
            messageBean.setData(resultMap);
        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<String> xData = new ArrayList<>();
            List<Integer> yData = new ArrayList<>();
            List<AlarmCountMalfunction> QATList = alarmService.queryStationAlarmTop();
            for (int i = 0; i < QATList.size(); i++) {
            	xData.add(QATList.get(i).getStationCn());
            	yData.add(QATList.get(i).getCntAlarmSystem());
			}
            resultMap.put("xData", xData);
            resultMap.put("yData", yData);
            messageBean.setData(resultMap);
        }
        return messageBean;
    }

    /**
     * 首页全网线路故障统计
     *
     * @return
     */
    @RequestMapping("/alarm/indexGetAlarmSum")
    @ResponseBody
    public MessageBean indexGetAlarmSum() {
        MessageBean messageBean = new MessageBean();
        List<Map> typeList = new ArrayList<Map>();
        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
        if (StartUpClass.indexGetAlarmSum.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            resultMap.put("1", new int[]{648, 843212});
            resultMap.put("2", new int[]{328, 543777});
            resultMap.put("3", new int[]{348, 543212});
            resultMap.put("4", new int[]{532, 442123});
            resultMap.put("6", new int[]{879, 768555});
            resultMap.put("7", new int[]{220, 563312});
            resultMap.put("8", new int[]{435, 890721});
            resultMap.put("12", new int[]{655, 415687});

            Set entrySet = resultMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("Line", (String) m.getKey());
                item.put("number", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);

        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<Integer> list12 = alarmService.queryAlarmLineMalfunction();
            resultMap.put("1", new int[]{648, 843212});
            resultMap.put("2", new int[]{328, 543777});
            resultMap.put("3", new int[]{348, 543212});
            resultMap.put("4", new int[]{532, 442123});
            resultMap.put("6", new int[]{879, 768555});
            resultMap.put("7", new int[]{220, 563312});
            resultMap.put("8", new int[]{435, 890721});
            resultMap.put("12", list12);
            Set entrySet = resultMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("Line", (String) m.getKey());
                item.put("number", m.getValue());
                typeList.add(item);
            }
            messageBean.setData(typeList);
        }
        return messageBean;
    }

    /**
     * 首页全网实时报警
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/alarm/indexGetAlarmRealTime")
    @ResponseBody
    public MessageBean indexGetAlarmRealTime() throws Exception {
        MessageBean messageBean = new MessageBean();
        List<AlarmMessageBean> alarmMessageBeans = new ArrayList<>();
        if (StartUpClass.indexGetAlarmRealTime.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            alarmMessageBeans.add(new AlarmMessageBean(null, "EMCS", "诸光路上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", "station0135", null, null));
            alarmMessageBeans.add(new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", "station0134", null, null));
            alarmMessageBeans.add(new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", "station0135", null, null));
            alarmMessageBeans.add(new AlarmMessageBean(null, "BAS", "莲花路3号闸机票仓将满信号报警", sdf.format(new Date()), 3, "三级", "station0113", null, null));

            messageBean.setData(alarmMessageBeans);
        } else {
            Properties pt = PropertiesUtil.loadConfig("metro_support_backend/src/main/resources/stationId.properties");
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<AlarmMessageBean> alarmData = alarmService.queryAlarmData();
            for (AlarmMessageBean alarmMessageBean : alarmData) {
                String stationId = String.valueOf(pt.get(alarmMessageBean.getStationCn()));
                alarmMessageBean.setStationId(stationId);
                Integer alarmRank = alarmMessageBean.getAlarmRank();
                if (alarmRank == 1) {
                    alarmMessageBean.setAlarmLevel("一级");
                } else if (alarmRank == 2) {
                    alarmMessageBean.setAlarmLevel("二级");
                } else if (alarmRank == 3) {
                    alarmMessageBean.setAlarmLevel("三级");
                } else if (alarmRank == 4) {
                    alarmMessageBean.setAlarmLevel("四级");
                }
                alarmMessageBeans.add(alarmMessageBean);
            }

            messageBean.setData(alarmMessageBeans);

        }
        return messageBean;
    }

    /**
     * 首页线路报警
     *
     * @return
     */
    @RequestMapping("/alarm/indexGetAlarmRealTimeWithLine")
    @ResponseBody
    public MessageBean indexGetAlarmRealTimeWithLine() {
        MessageBean messageBean = new MessageBean();
        Map<String, List<AlarmMessageBean>> resultMap = new HashMap<>();
        if (StartUpClass.indexGetAlarmRealTimeWithLine.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            List<AlarmMessageBean> line1AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean1 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean1.setStationCn("上海南站");
            bean1.setStationEn("SHN");
            line1AlarmMessageBean.add(bean1);
            resultMap.put("line1", line1AlarmMessageBean);

            List<AlarmMessageBean> line2AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean2 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean2.setStationCn("龙阳路");
            bean2.setStationEn("LYL");
            AlarmMessageBean bean3 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean3.setStationCn("广兰路");
            bean3.setStationEn("GLL");
            line2AlarmMessageBean.add(bean2);
            line2AlarmMessageBean.add(bean3);
            resultMap.put("line2", line2AlarmMessageBean);

            List<AlarmMessageBean> line3AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean4 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean4.setStationCn("龙漕路");
            bean4.setStationEn("LCL");
            line3AlarmMessageBean.add(bean4);
            resultMap.put("line3", line3AlarmMessageBean);

            List<AlarmMessageBean> line4AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean5 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean5.setStationCn("宜山路");
            bean5.setStationEn("YSL");
            line4AlarmMessageBean.add(bean5);
            resultMap.put("line4", line4AlarmMessageBean);

            List<AlarmMessageBean> line6AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean6 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean6.setStationCn("上南路");
            bean6.setStationEn("SNL");
            line6AlarmMessageBean.add(bean6);
            resultMap.put("line6", line6AlarmMessageBean);

            List<AlarmMessageBean> line7AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean7 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean7.setStationCn("花木路");
            bean7.setStationEn("HML");
            line7AlarmMessageBean.add(bean7);
            resultMap.put("line7", line7AlarmMessageBean);

            List<AlarmMessageBean> line8AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean8 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean8.setStationCn("曲阜路");
            bean8.setStationEn("QFL");
            line8AlarmMessageBean.add(bean8);
            resultMap.put("line8", line8AlarmMessageBean);

            List<AlarmMessageBean> line12AlarmMessageBean = new ArrayList<>();
            AlarmMessageBean bean9 = new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", null, null, null);
            bean9.setStationCn("龙华西路");
            bean9.setStationEn("LHX");
            line12AlarmMessageBean.add(bean9);
            resultMap.put("line12", line12AlarmMessageBean);

            messageBean.setData(resultMap);
        } else {

        }
        return messageBean;
    }

    /**
     * @return 综合监视实时报警
     */
    @RequestMapping("/alarm/realTimeAlerts")
    @ResponseBody
    public MessageBean realTimeAlerts() throws Exception {

        MessageBean messageBean = new MessageBean();
        List<AlarmMessageBean> alarmMessageBeans = new ArrayList<>();
        if (StartUpClass.realTimeAlerts.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            alarmMessageBeans.add(new AlarmMessageBean(null, "EMCS", "诸光路上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", "station0135", null, null));
            alarmMessageBeans.add(new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", "station0134", null, null));
            alarmMessageBeans.add(new AlarmMessageBean(null, "EMCS", "上海南站上行1号扶梯急停信号报警", sdf.format(new Date()), 1, "一级", "station0135", null, null));
            alarmMessageBeans.add(new AlarmMessageBean(null, "BAS", "莲花路3号闸机票仓将满信号报警", sdf.format(new Date()), 3, "三级", "station0113", null, null));
            messageBean.setData(alarmMessageBeans);
        } else {
            Properties pt = PropertiesUtil.loadConfig("stationId.properties");
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<AlarmMessageBean> alarmData = alarmService.queryRealTimeAlarmData();
            for (AlarmMessageBean alarmMessageBean : alarmData) {
                String stationId = String.valueOf(pt.get(alarmMessageBean.getStationCn()));
                alarmMessageBean.setStationId(stationId);
                Integer alarmRank = alarmMessageBean.getAlarmRank();
                if (alarmRank == 1) {
                    alarmMessageBean.setAlarmLevel("一级");
                } else if (alarmRank == 2) {
                    alarmMessageBean.setAlarmLevel("二级");
                } else if (alarmRank == 3) {
                    alarmMessageBean.setAlarmLevel("三级");
                } else if (alarmRank == 4) {
                    alarmMessageBean.setAlarmLevel("四级");
                }
                alarmMessageBeans.add(alarmMessageBean);
            }

            messageBean.setData(alarmMessageBeans);
        }
        return messageBean;

    }


    /**
     * @return 综合监视一周报警分级统计
     */
    @RequestMapping("/alarm/alarmGradingStatistics")
    @ResponseBody
    public MessageBean alarmGradingStatistics() {
        MessageBean messageBean = new MessageBean();
        Map<String, int[]> resultMap = new HashMap<>();
        List<Map> typeList = new ArrayList<Map>();
        if (StartUpClass.alarmGradingStatistics.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            resultMap.put("TheFaultOf", new int[]{7, 30});
            resultMap.put("FailureRate", new int[]{100, 75});
            Set<Entry<String, int[]>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, int[]>> it = entrySet.iterator();
            while (it.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);

        } else {


        }

        return messageBean;

    }

    /**
     * @return 综合监视一周服务运维统计
     */
    @RequestMapping("/alarm/operationalStatistics")
    @ResponseBody
    public MessageBean operationalStatistics() {
        MessageBean messageBean = new MessageBean();
        Map<String, String> resultMap = new LinkedHashMap<>();
        List<Map> typeList = new ArrayList<Map>();
        if (StartUpClass.operationalStatistics.equals("test")) {

            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            resultMap.put("工单完成率", "1");
            resultMap.put("工单响应率", "1");
            resultMap.put("紧急工单率", "0");
            resultMap.put("严重工单率", "0");

            Set<Entry<String, String>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, String>> it = entrySet.iterator();
            while (it.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                typeList.add(item);
            }


            messageBean.setData(typeList);

        } else {


        }

        return messageBean;

    }


    /**
     * @return 综合监视车站故障总览
     */
    @RequestMapping("/alarm/overviewOfStation")
    @ResponseBody
    public MessageBean overviewOfStation(@RequestBody(required = false) String line) throws Exception {

        MessageBean messageBean = new MessageBean();

        Map<String, Object> line17 = alarmService.queryAllLineFault();
        Map<String, String> line1 = new HashMap<>();
        Map<String, String> line2 = new HashMap<>();
        Map<String, String> line3 = new HashMap<>();
        Map<String, String> line4 = new HashMap<>();
        Map<String, String> line6 = new HashMap<>();
        Map<String, String> line7 = new HashMap<>();
        Map<String, String> line8 = new HashMap<>();
        Map<String, String> line12 = new HashMap<>();

        Map<String, List> lineMap = new HashMap<>();
        Map<String, List> lineMap2 = new HashMap<>();
        List<Map> typeList1 = new ArrayList<Map>();
        List<Map> typeList2 = new ArrayList<Map>();
        List<Map> typeList3 = new ArrayList<Map>();
        List<Map> typeList4 = new ArrayList<Map>();
        List<Map> typeList6 = new ArrayList<Map>();
        List<Map> typeList7 = new ArrayList<Map>();
        List<Map> typeList8 = new ArrayList<Map>();
        List<Map> typeList12 = new ArrayList<Map>();
        List<Map> typeList17 = new ArrayList<Map>();
        line1.put("station0138", "0");
        line1.put("station0137", "0");
        line1.put("station0136", "0");
        line1.put("station0135", "1");
        line1.put("station0134", "0");
        line1.put("station0133", "0");

        line2.put("station0234", "0");
        line2.put("station0235", "1");
        line2.put("station0236", "2");
        line2.put("station0237", "3");
        line2.put("station0238", "0");
        line2.put("station0239", "4");

        line3.put("station0317", "1");
        line3.put("station0316", "0");
        line3.put("station0315", "0");
        line3.put("station0314", "0");
        line3.put("station0313", "2");
        line3.put("station0312", "0");
        line3.put("station0311", "3");

        line4.put("station0425", "1");
        line4.put("station0426", "1");
        line4.put("station0401", "1");
        line4.put("station0402", "1");
        line4.put("station0403", "0");
        line4.put("station0404", "0");
        line4.put("station0405", "0");

        line6.put("station0626", "1");
        line6.put("station0625", "0");
        line6.put("station0624", "0");
        line6.put("station0623", "0");
        line6.put("station0622", "2");
        line6.put("station0621", "0");

        line7.put("station0748", "0");
        line7.put("station0749", "3");
        line7.put("station0750", "1");
        line7.put("station0751", "1");
        line7.put("station0752", "1");
        line7.put("station0753", "1");

        line8.put("station0826", "0");
        line8.put("station0825", "0");
        line8.put("station0824", "0");
        line8.put("station0823", "2");
        line8.put("station0822", "0");
        line8.put("station0821", "3");
        line8.put("station0820", "1");

//        line17.put("station_HJR","1");
//        line17.put("station_ZXS","2");
//        line17.put("station_XYR","3");
//        line17.put("station_NXJ","4");
//        line17.put("station_PLR","2");
//        line17.put("station_PLR","1");


        Set<String> keySet1 = line1.keySet();
        Iterator<String> it1 = keySet1.iterator();
        while (it1.hasNext()) {
            Map<String, Object> item = new HashMap<String, Object>();
            String station = it1.next();
            item.put("stationId", station);
            String state = line1.get(station);
            item.put("state", state);
            typeList1.add(item);

        }

        Set<Entry<String, String>> entrySet2 = line2.entrySet();
        Iterator<Entry<String, String>> it2 = entrySet2.iterator();
        while (it2.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it2.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList2.add(item);
        }

        Set<Entry<String, String>> entrySet3 = line3.entrySet();
        Iterator<Entry<String, String>> it3 = entrySet3.iterator();
        while (it3.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it3.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList3.add(item);
        }

        Set<Entry<String, String>> entrySet4 = line4.entrySet();
        Iterator<Entry<String, String>> it4 = entrySet4.iterator();
        while (it4.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it4.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList4.add(item);
        }

        Set<Entry<String, String>> entrySet6 = line6.entrySet();
        Iterator<Entry<String, String>> it6 = entrySet6.iterator();
        while (it6.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it6.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList6.add(item);
        }

        Set<Entry<String, String>> entrySet7 = line7.entrySet();
        Iterator<Entry<String, String>> it7 = entrySet7.iterator();
        while (it7.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it7.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList7.add(item);
        }

        Set<Entry<String, String>> entrySet8 = line8.entrySet();
        Iterator<Entry<String, String>> it8 = entrySet8.iterator();
        while (it8.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it8.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList8.add(item);
        }

        Set<Entry<String, Object>> entrySet17 = line17.entrySet();
        Iterator<Entry<String, Object>> it17 = entrySet17.iterator();
        while (it17.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it17.next();

                if (!"null".equals(m.getKey())){
                    item.put("stationId", m.getKey());
                    item.put("state", m.getValue());
                }

            typeList17.add(item);
        }

        Set<Entry<String, String>> entrySet12 = line12.entrySet();
        Iterator<Entry<String, String>> it12 = entrySet12.iterator();
        while (it12.hasNext()) {

            Map<String, Object> item = new HashMap<String, Object>();
            Entry m = (Entry) it12.next();
            item.put("stationId", m.getKey());
            item.put("state", m.getValue());

            typeList12.add(item);
        }



        lineMap2.put("line1", typeList1);
        lineMap2.put("line2", typeList2);
        lineMap2.put("line3", typeList3);
        lineMap2.put("line4", typeList4);
        lineMap2.put("line6", typeList6);
        lineMap2.put("line7", typeList7);
        lineMap2.put("line8", typeList8);
        lineMap2.put("line12", typeList12);
        lineMap2.put("line17", typeList17);

        if (StartUpClass.overviewOfStation.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            if (StringUtils.isBlank(line)) {

                lineMap.put("line1", typeList1);
                lineMap.put("line2", typeList2);
                lineMap.put("line3", typeList3);
                lineMap.put("line4", typeList4);
                lineMap.put("line6", typeList6);
                lineMap.put("line7", typeList7);
                lineMap.put("line8", typeList8);
                lineMap.put("line12", typeList12);
                lineMap.put("line17", typeList17);

                messageBean.setData(lineMap);

            } else {
                Map po = JSON.parseObject(line, Map.class);
                String str = "line" + po.get("line");
                lineMap.put(str, lineMap2.get(str));
                messageBean.setData(lineMap);
            }


        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            lineMap2.put("line1", typeList1);
            lineMap2.put("line2", typeList2);
            lineMap2.put("line3", typeList3);
            lineMap2.put("line4", typeList4);
            lineMap2.put("line6", typeList6);
            lineMap2.put("line7", typeList7);
            lineMap2.put("line8", typeList8);
            lineMap2.put("line12", typeList12);
            lineMap2.put("line17", typeList17);


            if (StringUtils.isBlank(line)) {
                lineMap.put("line1", typeList1);
                lineMap.put("line2", typeList2);
                lineMap.put("line3", typeList3);
                lineMap.put("line4", typeList4);
                lineMap.put("line6", typeList6);
                lineMap.put("line7", typeList7);
                lineMap.put("line8", typeList8);
                lineMap.put("line12",typeList12);
                lineMap.put("line17",typeList17);

                messageBean.setData(lineMap);

            } else {
                Map po = JSON.parseObject(line, Map.class);
                String str = "line" + po.get("line");
                lineMap.put(str, lineMap2.get(str));
                messageBean.setData(lineMap);
            }

        }

        return messageBean;

    }


    /**
     * 综合监视综合信息车站故障统计TOP10
     *
     * @return
     */
    @RequestMapping("/alarm/stationAlarmTop")
    @ResponseBody
    public MessageBean stationAlarmTop() {
        MessageBean messageBean = new MessageBean();
        Map<String, Object> resultMap = new HashMap<>();
        if (StartUpClass.stationAlarmTop.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            String[] xData = new String[]{
                    "常熟路", "陕西南路", "人民广场", "汉中路", "徐家汇", "漕宝路", "上海南站", "莘庄"
            };
            int[] yData = new int[]{
                    230, 220, 205, 180, 170, 168, 165, 100
            };
            resultMap.put("xData", xData);
            resultMap.put("yData", yData);
            messageBean.setData(resultMap);
        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<AlarmCountMalfunction> alarmCountTops = alarmService.queryAlarmTop();
            List<String> xData = new ArrayList<>();
            List<Integer> yData = new ArrayList<>();
            for (AlarmCountMalfunction alarmCountTop : alarmCountTops) {
                xData.add(alarmCountTop.getStationCn());
                yData.add(alarmCountTop.getCntAlarmSystem());
                resultMap.put("xData", xData);
                resultMap.put("yData", yData);
            }
            messageBean.setData(resultMap);
        }
        return messageBean;
    }


    /**
     * @return 综合监视车站分类统计
     */
    @RequestMapping("/alarm/classifiedStatistic")
    @ResponseBody
    public MessageBean classifiedStatistic() {
        MessageBean messageBean = new MessageBean();
        Map<String, String> CPUMap = new HashMap<>();
        Map<String, String> internalStorageMap = new HashMap<>();
        Map<String, String> magneticDiskMap = new HashMap<>();
        Map<String, String> rateOfFlowMap = new HashMap<>();
        Map<String, Map> resultMap = new HashMap<>();
        List<Map> typeList = new ArrayList<Map>();
        if (StartUpClass.classifiedStatistic.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            CPUMap.put("实时服务器1", "34");
            CPUMap.put("接口服务器1", "31");
            CPUMap.put("接口服务器2", "20");
            internalStorageMap.put("历史服务器1", "25");
            internalStorageMap.put("实时服务器1", "21");
            internalStorageMap.put("接口转发服务器1", "10");
            magneticDiskMap.put("历史服务器1", "23");
            magneticDiskMap.put("历史服务器2", "22");
            magneticDiskMap.put("接口转发服务器1", "10");
            rateOfFlowMap.put("接口转发服务器1", "23");
            rateOfFlowMap.put("远程FEP1", "21");
            rateOfFlowMap.put("远程FEP2", "10");

            resultMap.put("CPU TOP3", CPUMap);
            resultMap.put("内存 TOP3", internalStorageMap);
            resultMap.put("磁盘 TOP3", magneticDiskMap);
            resultMap.put("流量 TOP3", rateOfFlowMap);

            Set<Entry<String, Map>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, Map>> it = entrySet.iterator();
            while (it.hasNext()) {

                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();
                item.put("name", m.getKey());
                item.put("value", m.getValue());

                typeList.add(item);
            }


            messageBean.setData(typeList);


            //messageBean.setData(resultMap);

        } else {


        }

        return messageBean;

    }


    /**
     * @return 综合监视车站接口状态
     */
    @RequestMapping("/alarm/interfaceStatus")
    @ResponseBody
    public MessageBean interfaceStatus() {
        MessageBean messageBean = new MessageBean();
        Map<String, Integer> resultMap = new HashMap<>();
        List<Map> StatuList = new ArrayList<Map>();
        if (StartUpClass.interfaceStatus.equals("test")) {

            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            resultMap.put("EMCS", 1);
            resultMap.put("FAS", 1);
            resultMap.put("PSCADA", 1);
            resultMap.put("CCTV", 1);
            resultMap.put("PA", 1);
            resultMap.put("ATS", 0);

            Set<Entry<String, Integer>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, Integer>> it = entrySet.iterator();
            while (it.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                StatuList.add(item);
            }

            messageBean.setData(StatuList);

        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<String> devices = alarmService.queryDevicePort();
            for (String device:devices) {
                resultMap.put(device,1);
            }
            resultMap.put("CCTV",1);
            resultMap.put("PA",1);

            Set<Entry<String, Integer>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, Integer>> it = entrySet.iterator();
            while (it.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                StatuList.add(item);
            }



            messageBean.setData(StatuList);
        }

        return messageBean;

    }


    /**
     * @return 设备管理设备分类统计
     */
    @RequestMapping("/alarm/classificationOfEquipment")
    @ResponseBody
    public MessageBean classificationOfEquipment() {
        MessageBean messageBean = new MessageBean();
        Map<String, String> resultMap = new HashMap<>();
        List<Map> typeList = new ArrayList<Map>();
        if (StartUpClass.classificationOfEquipment.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            resultMap.put("EMCS", "20.90");
            resultMap.put("FAS", "17.91");
            resultMap.put("PSCADA", "29.85");
            resultMap.put("CCTV", "17.91");
            resultMap.put("PSD", "13.43");

            Set<Entry<String, String>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, String>> it = entrySet.iterator();
            while (it.hasNext()) {

                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();

                item.put("system", m.getKey());
                item.put("proportion", m.getValue());

                typeList.add(item);
            }


            messageBean.setData(typeList);

        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            resultMap = alarmService.queryAlarmSystem();
            Set<Entry<String, String>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, String>> it = entrySet.iterator();
            while (it.hasNext()) {

                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();

                item.put("system", m.getKey());
                item.put("proportion", m.getValue());

                typeList.add(item);
            }


            messageBean.setData(typeList);
        }

        return messageBean;

    }

    /**
     * @return 设备管理故障统计
     */
    @RequestMapping("/alarm/deviceFailureStatistics")
    @ResponseBody
    public MessageBean deviceFailureStatistics() {
        MessageBean messageBean = new MessageBean();
        Map<String, Integer> resultMap = new HashMap<>();
        List<Map> typeList = new ArrayList<Map>();
        if (StartUpClass.deviceFailureStatistics.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            resultMap.put("FAS", 50);
            resultMap.put("PSCADA", 55);
            resultMap.put("CCTV", 25);
            resultMap.put("PA", 30);
            resultMap.put("ATS", 5);
            resultMap.put("PSD", 40);

            Set<Entry<String, Integer>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, Integer>> it = entrySet.iterator();
            while (it.hasNext()) {

                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();

                item.put("system", m.getKey());
                item.put("quantity", m.getValue());
                typeList.add(item);
            }
            messageBean.setData(typeList);

        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<AlarmCountMalfunction> alarmCountMalfunctions = alarmService.queryMalfunctionCnt();
            for (AlarmCountMalfunction alarmCountMalfunction : alarmCountMalfunctions) {
                resultMap.put(alarmCountMalfunction.getAlarmSystem(), alarmCountMalfunction.getCntAlarmSystem());

            }
            Set entrySet = resultMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("system", (String) m.getKey());
                item.put("quantity", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);
        }
        return messageBean;

    }

    /**
     * @return 设备管理系统健康值
     */
    @RequestMapping("/alarm/systemHealthValue")
    @ResponseBody
    public MessageBean systemHealthValue() {
        MessageBean messageBean = new MessageBean();

        List<Map> typeList = new ArrayList<Map>();
        Map<String, Integer> resultMap = new HashMap<>();
        Map<String, Double> resultMapDouble = new HashMap<>();
        if (StartUpClass.systemHealthValue.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            resultMap.put("EMCS", 98);
            resultMap.put("FAS", 99);
            resultMap.put("PSCADA", 96);

            Set<Entry<String, Integer>> entrySet = resultMap.entrySet();
            Iterator<Entry<String, Integer>> it = entrySet.iterator();
            while (it.hasNext()) {

                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();

                item.put("system", (String) m.getKey());
                item.put("healthIndex", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);

        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            resultMapDouble = alarmService.systemHealthValue();
            Set<Entry<String, Double>> entrySet = resultMapDouble.entrySet();
            Iterator<Entry<String, Double>> it = entrySet.iterator();
            while (it.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it.next();
                item.put("system", (String) m.getKey());
                item.put("healthIndex", m.getValue());
                typeList.add(item);
            }
            messageBean.setData(typeList);
        }
        return messageBean;
    }


    /**
     * @return 数据分析全线车站故障统计
     */
    @RequestMapping("/alarm/allLineStationFaultStatistics")
    @ResponseBody
    public MessageBean allLineStationFaultStatistics() {
        MessageBean messageBean = new MessageBean();
        List<AllLineStationFault> statistics = new ArrayList<>();
        if (StartUpClass.allLineStationFaultStatistics.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            statistics.add(new AllLineStationFault("1", "莘庄站", "500", "1000"));
            statistics.add(new AllLineStationFault("2", "外环路站", "500", "1000"));
            statistics.add(new AllLineStationFault("3", "莲花站", "500", "1000"));
            statistics.add(new AllLineStationFault("4", "锦江乐园站", "500", "1000"));
            statistics.add(new AllLineStationFault("5", "上海南站", "500", "1000"));
            statistics.add(new AllLineStationFault("6", "漕宝站", "500", "1000"));
            statistics.add(new AllLineStationFault("7", "上海体育馆站", "500", "1000"));
            statistics.add(new AllLineStationFault("8", "徐家汇站", "500", "1000"));
            statistics.add(new AllLineStationFault("9", "衡山路站", "500", "1000"));
            statistics.add(new AllLineStationFault("10", "常熟路站", "500", "1000"));
            statistics.add(new AllLineStationFault("11", "陕西南路站", "500", "1000"));

            messageBean.setData(statistics);

        } else {
            messageBean.setMessage(StringHelper.MESSAGE_TYPE_SUCCESS);
            List<AllLineStationFault> asfs = alarmService.queryAllLineCntFault();
            for (AllLineStationFault asf:asfs) {
                statistics.add(asf);
            }
            messageBean.setData(statistics);
        }

        return messageBean;

    }


    /**
     * @return 数据分析重要设备故障统计TOP10
     */
    @RequestMapping("/alarm/inportDeviceTop")
    @ResponseBody
    public MessageBean inportDeviceTop() {
        MessageBean messageBean = new MessageBean();
        Map<String, Object> resultMap = new HashMap<>();
        if (StartUpClass.inportDeviceTop.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            String[] xData = new String[]{
                    "风阀", "风机", "水泵", "烟感", "温感", "手报", "站台门", "传感器", "防火阀", "开关"
            };
            int[] yData = new int[]{
                    110, 102, 96, 90, 83, 76, 68, 59, 50, 52
            };
            resultMap.put("xData", xData);
            resultMap.put("yData", yData);
            messageBean.setData(resultMap);
        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
    		resultMap = alarmService.queryDeviceTopTen();
    		messageBean.setData(resultMap);
        }
        return messageBean;
    }

    /**
     * 数据分析各级别故障统计
     *
     * @return
     */
    @RequestMapping("/alarm/faultStatisticsAllLevels")
    @ResponseBody
    public MessageBean faultStatisticsAllLevels() {
        MessageBean messageBean = new MessageBean();

        List<Map> typeList = new ArrayList<Map>();
        Map<String, Integer> resultMap = new HashMap<String, Integer>();
        if (StartUpClass.faultStatisticsAllLevels.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);

            resultMap.put("一级", 10);
            resultMap.put("二级", 20);
            resultMap.put("三级", 30);
            resultMap.put("四级", 60);

            Set entrySet = resultMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("name", (String) m.getKey());
                item.put("value", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);

        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            Map<String, Integer> stringIntegerMap = alarmService.queryMalfunctionRank();
            Set entrySet = stringIntegerMap.entrySet();
            Iterator it2 = entrySet.iterator();

            while (it2.hasNext()) {
                Map<String, Object> item = new HashMap<String, Object>();
                Entry m = (Entry) it2.next();
                item.put("name", m.getKey());
                item.put("value", m.getValue());
                typeList.add(item);
            }

            messageBean.setData(typeList);
        }
        return messageBean;
    }


    /**
     * @return 数据分析全线实时报警
     */
    @RequestMapping("/alarm/allLineRealAlarm")
    @ResponseBody
    public MessageBean allLineRealAlarm(@RequestBody(required = false) AlarmQuery alarmQuery) {
        MessageBean messageBean = new MessageBean();
        List<AllLineRealAlarm> statistics = new ArrayList<>();
        if (StartUpClass.allLineRealAlarm.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            if (alarmQuery != null) {
                statistics.add(new AllLineRealAlarm(sdf.format(new Date()), "虹梅路", "FAS", "高", "0", "站台设备区-感温探测器504故障", "0", "故障", null));
                statistics.add(new AllLineRealAlarm(sdf.format(new Date()), "莘庄站", "FAS", "中", "0", "站台设备区-感温探测器504故障", "1", "故障", null));
            } else {
                statistics.add(new AllLineRealAlarm(sdf.format(new Date()), "虹梅路", "FAS", "高", "0", "站台设备区-感温探测器504故障", "0", "故障", null));
                statistics.add(new AllLineRealAlarm(sdf.format(new Date()), "莘庄站", "FAS", "中", "0", "站台设备区-感温探测器504故障", "1", "故障", null));
                statistics.add(new AllLineRealAlarm(sdf.format(new Date()), "虹梅路", "FAS", "低", "0", "站台设备区-感温探测器504故障", "0", "故障", null));
                statistics.add(new AllLineRealAlarm(sdf.format(new Date()), "虹梅路", "FAS", "紧急", "1", "站台设备区-感温探测器505火灾报警", "0", "报警", sdf.format(new Date())));
            }
            messageBean.setData(statistics);

        } else {
            if (null != alarmQuery) {
                messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
                String alarmRank = alarmQuery.getRank();
                if (null!=alarmRank){
                    switch (alarmRank){
                        case "低":
                            alarmQuery.setRank("4");
                            break;
                        case "中":
                            alarmQuery.setRank("3");
                            break;
                        case "高":
                            alarmQuery.setRank("2");
                            break;
                        case "紧急":
                            alarmQuery.setRank("1");
                            break;
                        default:
                            alarmQuery.setRank("");
                    }
                }
                List<AllLineRealAlarm> allLineRealAlarms = alarmService.queryRealTimeAlarm(alarmQuery);
                for (AllLineRealAlarm allLineRealAlarm : allLineRealAlarms) {
                    String rank = allLineRealAlarm.getRank();
                    String alarmStatus = allLineRealAlarm.getAlarmStatus();
                    if (rank.equals("1")){
                        allLineRealAlarm.setRank("紧急");
                    }else if (rank.equals("2")){
                        allLineRealAlarm.setRank("高");
                    }else if (rank.equals("3")) {
                        allLineRealAlarm.setRank("中");
                    }else if (rank.equals("4")) {
                        allLineRealAlarm.setRank("低");
                    }
                    if(alarmStatus.equals("0000")){
                        allLineRealAlarm.setAlarmStatus("0");
                        allLineRealAlarm.setAlarmValue("故障");
                        allLineRealAlarm.setRecoveryTime(null);
                    }else if(alarmStatus.equals("0001")){
                        allLineRealAlarm.setAlarmStatus("1");
                        allLineRealAlarm.setAlarmValue("报警");

                    }
                    statistics.add(allLineRealAlarm);
                }
            } else {
                messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
                List<AllLineRealAlarm> allLineRealAlarms = alarmService.queryAllLineRealTimeAlarm();
                for (AllLineRealAlarm allLineRealAlarm : allLineRealAlarms) {
                    String alarmStatus = allLineRealAlarm.getAlarmStatus();
                    String rank = allLineRealAlarm.getRank();
                    if (rank.equals("4")){
                        allLineRealAlarm.setRank("低");
                    }else if (rank.equals("3")){
                        allLineRealAlarm.setRank("中");
                    }else if (rank.equals("2")) {
                        allLineRealAlarm.setRank("高");
                    }else if (rank.equals("1")) {
                        allLineRealAlarm.setRank("紧急");
                    }
                    if(alarmStatus.equals("0000")){
                        allLineRealAlarm.setAlarmStatus("0");
                        allLineRealAlarm.setAlarmValue("故障");
                        allLineRealAlarm.setRecoveryTime(null);
                    }else if(alarmStatus.equals("0001")){
                        allLineRealAlarm.setAlarmStatus("1");
                        allLineRealAlarm.setAlarmValue("报警");
                        allLineRealAlarm.setRecoveryTime(allLineRealAlarm.getRecoveryTime());
                    }
                    statistics.add(allLineRealAlarm);
                }
            }
            messageBean.setData(statistics);

        }

        return messageBean;

    }

    /**
     * 数据分析重要设备健康指数
     *
     * @return
     */
    @RequestMapping("/alarm/indexImportDevice")
    @ResponseBody
    public MessageBean indexImportDevice() {
        MessageBean messageBean = new MessageBean();
        Map<String, Integer> resultMap = new HashMap<>();
        if (StartUpClass.indexImportDevice.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            resultMap.put("healthIndex", 86);
            messageBean.setData(resultMap);
        } else {
        	 messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
        	 int healthIndex = alarmService.getHealthIndex();
             resultMap.put("healthIndex", healthIndex);
             messageBean.setData(resultMap);
        }
        return messageBean;
    }


    /**
     * @return 数据分析重要设备健康度
     */
    @RequestMapping("/alarm/healthImportDevice")
    @ResponseBody
    public MessageBean healthImportDevice(HttpServletRequest req) {
        MessageBean messageBean = new MessageBean();
        List<HealthImportDevice> statistics = new ArrayList<>();
        if (StartUpClass.healthImportDevice.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            statistics.add(new HealthImportDevice("1", "感烟报警器", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("2", "感温报警器", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("3", "手报按钮", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("4", "35KV进线开关", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("5", "35KV出线开关", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("6", "35KV分段开关", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("7", "35KV整流变开关", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("8", "35KV电力变开关", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("9", "35KV变压器开关", "50", "1000", "5"));
            statistics.add(new HealthImportDevice("10", "1500V触网闸刀", "50", "1000", "5"));
            messageBean.setData(statistics);

        } else {
        	messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
        	
        	String curPage = req.getParameter("curPage");
        	String limit = req.getParameter("limit");
        	if(StringUtils.isBlank(curPage) || StringUtils.isBlank(curPage)){
        		
        		messageBean.setMessage("参数为空");
        		return messageBean;
        	}
        	QueryBase qb = new QueryBase();
        	qb.setStart(Integer.parseInt(curPage));
        	qb.setLimit(Integer.parseInt(limit));
    		List<HealthImportDevice> queryHealthImportDevice = alarmService.queryHealthImportDevice(qb);
    		int index = 1;
    		for (int i = 0; i < queryHealthImportDevice.size(); i++) {
    			HealthImportDevice healthImportDevice = queryHealthImportDevice.get(i);
    			healthImportDevice.setDeviceId(String.valueOf(index));
    			statistics.add(healthImportDevice);
    			index += 1 ;
			}
    		 messageBean.setData(statistics);
        }

        return messageBean;

    }


    /**
     * @return 数据分析重要设备风险指数排行榜
     */
    @RequestMapping("/alarm/inportDeviceRiskIndex")
    @ResponseBody
    public MessageBean inportDeviceRiskIndex() {
        MessageBean messageBean = new MessageBean();
        Map<String, Object> resultMap = new HashMap<>();
        if (StartUpClass.inportDeviceRiskIndex.equals("test")) {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            String[] xData = new String[]{
                    "风阀", "风机", "水泵", "烟感", "温感", "手报", "站台门", "传感器", "防火阀", "开关"
            };
            int[] yData = new int[]{
                    110, 102, 99, 90, 83, 67, 63, 57, 50, 43
            };
            resultMap.put("xData", xData);
            resultMap.put("yData", yData);
            messageBean.setData(resultMap);
        } else {
            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
        	try{
        	resultMap = alarmService.queryDevicePro();
        	messageBean.setData(resultMap);
        	}catch(Exception e){
        		logger.info("faild to get inportDeviceRiskIndex ! "); 
        	}
        }
        return messageBean;

    }


    /**
     * @return 数据分析获取下拉框选项
     */
    @RequestMapping("/alarm/getDropDownBox")
    @ResponseBody
    public MessageBean getDropDownBox(HttpServletRequest req) {
        MessageBean messageBean = new MessageBean();
        List<String> stations = new ArrayList<String>();
        List<String> systems = new ArrayList<String>();
        List<String> levels = new ArrayList<String>();
        Map<String, Object> resultMap = new HashMap<String, Object>();

        if (StartUpClass.getDropDownBox.equals("test")) {

            messageBean.setCode(StringHelper.MESSAGE_TYPE_SUCCESS);
            stations.add("东方绿洲站");
            stations.add("朱家角站");
            stations.add("淀山湖大道站");
            stations.add("漕盈路站");
            stations.add("青浦新城站");
            stations.add("汇金路站");
            stations.add("赵巷站");
            stations.add("嘉松中路站");
            stations.add("徐泾北城站");
            stations.add("徐盈路站");
            stations.add("蟠龙路站");
            stations.add("诸光路站");
            stations.add("虹桥火车站站");

            systems.add("FAS");
            systems.add("PSCADA");
            systems.add("EMCS");
            systems.add("ATS");
            systems.add("CCTV");
            systems.add("PA");

            levels.add("低");
            levels.add("中");
            levels.add("高");
            levels.add("紧急");

            resultMap.put("stations", stations);
            resultMap.put("systems", systems);
            resultMap.put("levels", levels);


            messageBean.setData(resultMap);

        } else {

        }

        return messageBean;

    }


}
